
// ***********************************************************************
// AUTO GENERATED CLASS - Do Not Modify this file, if needed modify .tt
// ***********************************************************************
// Assembly         : InnovaApp_DomainLayer
// Author           : LJO+01
// Created          : 17/11/2013 20:29:50
// ***********************************************************************
// <copyright file="N.A." company="Copyright © Innovacall 2011">
//     Copyright (c) . All rights reserved.
// </copyright>
// <summary>
// Domain layer  
// DomainClass
// </summary>
// ***********************************************************************

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;


namespace InnovaApp.Layers.DomainLayer
{
    /// <summary>
    /// Class Contact
    /// </summary>
    [Serializable]
    public partial class Contact : _DomainLayer_Base  
    {
        #region Primitive Properties
    	
        /// <summary>
        /// Gets or sets Id.
        /// </summary>
        /// <value>The Id.</value>
        public virtual int Id
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets FK_Language.
        /// </summary>
        /// <value>The FK_Language.</value>
        /// <remarks>
        /// Foregn key of Contact
        /// 
        /// </remarks>
        public virtual int FK_Language
        {
            get { return _fK_Language; }
            set
            {
                try
                {
                    _settingFK = true;
                    if (_fK_Language != value)
                    {
                        if (Language != null && Language.Id != value)
                        {
                            Language = null;
                        }
                        _fK_Language = value;
                    }
                }
                finally
                {
                    _settingFK = false;
                }
            }
        }
        private int _fK_Language;
    	
        /// <summary>
        /// Gets or sets FK_InnoAppUser.
        /// </summary>
        /// <value>The FK_InnoAppUser.</value>
        /// <remarks>
        /// Foregn key of Contact
        /// 
        /// </remarks>
        public virtual System.Guid FK_InnoAppUser
        {
            get { return _fK_InnoAppUser; }
            set
            {
                try
                {
                    _settingFK = true;
                    if (_fK_InnoAppUser != value)
                    {
                        if (InnoAppUser != null && InnoAppUser.Id != value)
                        {
                            InnoAppUser = null;
                        }
                        _fK_InnoAppUser = value;
                    }
                }
                finally
                {
                    _settingFK = false;
                }
            }
        }
        private System.Guid _fK_InnoAppUser;
    	
        /// <summary>
        /// Gets or sets FK_Genre.
        /// </summary>
        /// <value>The FK_Genre.</value>
        /// <remarks>
        /// Foregn key of Contact
        /// 
        /// </remarks>
        public virtual int FK_Genre
        {
            get { return _fK_Genre; }
            set
            {
                try
                {
                    _settingFK = true;
                    if (_fK_Genre != value)
                    {
                        if (Genre != null && Genre.Id != value)
                        {
                            Genre = null;
                        }
                        _fK_Genre = value;
                    }
                }
                finally
                {
                    _settingFK = false;
                }
            }
        }
        private int _fK_Genre;
    	
        /// <summary>
        /// Gets or sets FK_CalendarTimeZones.
        /// </summary>
        /// <value>The FK_CalendarTimeZones.</value>
        /// <remarks>
        /// Foregn key of Contact
        /// 
        /// </remarks>
        public virtual Nullable<int> FK_CalendarTimeZones
        {
            get { return _fK_CalendarTimeZones; }
            set
            {
                try
                {
                    _settingFK = true;
                    if (_fK_CalendarTimeZones != value)
                    {
                        if (CalendarTimeZones != null && CalendarTimeZones.Id != value)
                        {
                            CalendarTimeZones = null;
                        }
                        _fK_CalendarTimeZones = value;
                    }
                }
                finally
                {
                    _settingFK = false;
                }
            }
        }
        private Nullable<int> _fK_CalendarTimeZones;
    	
        /// <summary>
        /// Gets or sets FirstName.
        /// </summary>
        /// <value>The FirstName.</value>
        public virtual string FirstName
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets LastName.
        /// </summary>
        /// <value>The LastName.</value>
        public virtual string LastName
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets BirthDate.
        /// </summary>
        /// <value>The BirthDate.</value>
        public virtual Nullable<System.DateTime> BirthDate
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets IconPath.
        /// </summary>
        /// <value>The IconPath.</value>
        public virtual string IconPath
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets ImagePath.
        /// </summary>
        /// <value>The ImagePath.</value>
        public virtual string ImagePath
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets GoogleMapLat.
        /// </summary>
        /// <value>The GoogleMapLat.</value>
        public virtual Nullable<double> GoogleMapLat
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets GoogleMapLng.
        /// </summary>
        /// <value>The GoogleMapLng.</value>
        public virtual Nullable<double> GoogleMapLng
        {
            get;
            set;
        }
    	
        /// <summary>
        /// Gets or sets rowversion.
        /// </summary>
        /// <value>The rowversion.</value>
        public virtual byte[] rowversion
        {
            get;
            set;
        }

        #endregion

        #region Navigation Properties
        public virtual CalendarTimeZones CalendarTimeZones
        {
            get { return _calendarTimeZones; }
            set
            {
                if (!ReferenceEquals(_calendarTimeZones, value))
                {
                    var previousValue = _calendarTimeZones;
                    _calendarTimeZones = value;
                    FixupCalendarTimeZones(previousValue);
                }
            }
        }
        private CalendarTimeZones _calendarTimeZones;
    
        /// <summary>
        /// Link Contact to all ArticleComment
        /// </summary>
        public virtual ICollection<ArticleComment> ArticleComment
        {
            get
            {
                if (_articleComment == null)
                {
                    var newCollection = new FixupCollection<ArticleComment>();
                    newCollection.CollectionChanged += FixupArticleComment;
                    _articleComment = newCollection;
                }
                return _articleComment;
            }
            set
            {
                if (!ReferenceEquals(_articleComment, value))
                {
                    var previousValue = _articleComment as FixupCollection<ArticleComment>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupArticleComment;
                    }
                    _articleComment = value;
                    var newValue = value as FixupCollection<ArticleComment>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupArticleComment;
                    }
                }
            }
        }
        private ICollection<ArticleComment> _articleComment;
    
        /// <summary>
        /// Link Contact to all Contact_ContactAddress
        /// </summary>
        public virtual ICollection<Contact_ContactAddress> Contact_ContactAddress
        {
            get
            {
                if (_contact_ContactAddress == null)
                {
                    var newCollection = new FixupCollection<Contact_ContactAddress>();
                    newCollection.CollectionChanged += FixupContact_ContactAddress;
                    _contact_ContactAddress = newCollection;
                }
                return _contact_ContactAddress;
            }
            set
            {
                if (!ReferenceEquals(_contact_ContactAddress, value))
                {
                    var previousValue = _contact_ContactAddress as FixupCollection<Contact_ContactAddress>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupContact_ContactAddress;
                    }
                    _contact_ContactAddress = value;
                    var newValue = value as FixupCollection<Contact_ContactAddress>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupContact_ContactAddress;
                    }
                }
            }
        }
        private ICollection<Contact_ContactAddress> _contact_ContactAddress;
    
        /// <summary>
        /// Link Contact to all Contact_Competency
        /// </summary>
        public virtual ICollection<Contact_Competency> Contact_Competency
        {
            get
            {
                if (_contact_Competency == null)
                {
                    var newCollection = new FixupCollection<Contact_Competency>();
                    newCollection.CollectionChanged += FixupContact_Competency;
                    _contact_Competency = newCollection;
                }
                return _contact_Competency;
            }
            set
            {
                if (!ReferenceEquals(_contact_Competency, value))
                {
                    var previousValue = _contact_Competency as FixupCollection<Contact_Competency>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupContact_Competency;
                    }
                    _contact_Competency = value;
                    var newValue = value as FixupCollection<Contact_Competency>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupContact_Competency;
                    }
                }
            }
        }
        private ICollection<Contact_Competency> _contact_Competency;
        public virtual Genre Genre
        {
            get { return _genre; }
            set
            {
                if (!ReferenceEquals(_genre, value))
                {
                    var previousValue = _genre;
                    _genre = value;
                    FixupGenre(previousValue);
                }
            }
        }
        private Genre _genre;
        public virtual InnoAppUser InnoAppUser
        {
            get { return _innoAppUser; }
            set
            {
                if (!ReferenceEquals(_innoAppUser, value))
                {
                    var previousValue = _innoAppUser;
                    _innoAppUser = value;
                    FixupInnoAppUser(previousValue);
                }
            }
        }
        private InnoAppUser _innoAppUser;
        public virtual Language Language
        {
            get { return _language; }
            set
            {
                if (!ReferenceEquals(_language, value))
                {
                    var previousValue = _language;
                    _language = value;
                    FixupLanguage(previousValue);
                }
            }
        }
        private Language _language;
    
        /// <summary>
        /// Link Contact to all Contact_TelecomType
        /// </summary>
        public virtual ICollection<Contact_TelecomType> Contact_TelecomType
        {
            get
            {
                if (_contact_TelecomType == null)
                {
                    var newCollection = new FixupCollection<Contact_TelecomType>();
                    newCollection.CollectionChanged += FixupContact_TelecomType;
                    _contact_TelecomType = newCollection;
                }
                return _contact_TelecomType;
            }
            set
            {
                if (!ReferenceEquals(_contact_TelecomType, value))
                {
                    var previousValue = _contact_TelecomType as FixupCollection<Contact_TelecomType>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupContact_TelecomType;
                    }
                    _contact_TelecomType = value;
                    var newValue = value as FixupCollection<Contact_TelecomType>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupContact_TelecomType;
                    }
                }
            }
        }
        private ICollection<Contact_TelecomType> _contact_TelecomType;
    
        /// <summary>
        /// Link Contact to all Order
        /// </summary>
        public virtual ICollection<Order> Order
        {
            get
            {
                if (_order == null)
                {
                    var newCollection = new FixupCollection<Order>();
                    newCollection.CollectionChanged += FixupOrder;
                    _order = newCollection;
                }
                return _order;
            }
            set
            {
                if (!ReferenceEquals(_order, value))
                {
                    var previousValue = _order as FixupCollection<Order>;
                    if (previousValue != null)
                    {
                        previousValue.CollectionChanged -= FixupOrder;
                    }
                    _order = value;
                    var newValue = value as FixupCollection<Order>;
                    if (newValue != null)
                    {
                        newValue.CollectionChanged += FixupOrder;
                    }
                }
            }
        }
        private ICollection<Order> _order;

        #endregion

        #region Association Fixup
    
        private bool _settingFK = false;
    
        private void FixupCalendarTimeZones(CalendarTimeZones previousValue)
        {
            if (previousValue != null && previousValue.Contact.Contains(this))
            {
                previousValue.Contact.Remove(this);
            }
    
            if (CalendarTimeZones != null)
            {
                if (!CalendarTimeZones.Contact.Contains(this))
                {
                    CalendarTimeZones.Contact.Add(this);
                }
                if (FK_CalendarTimeZones != CalendarTimeZones.Id)
                {
                    FK_CalendarTimeZones = CalendarTimeZones.Id;
                }
            }
            else if (!_settingFK)
            {
                FK_CalendarTimeZones = null;
            }
        }
    
        private void FixupGenre(Genre previousValue)
        {
            if (previousValue != null && previousValue.Contact.Contains(this))
            {
                previousValue.Contact.Remove(this);
            }
    
            if (Genre != null)
            {
                if (!Genre.Contact.Contains(this))
                {
                    Genre.Contact.Add(this);
                }
                if (FK_Genre != Genre.Id)
                {
                    FK_Genre = Genre.Id;
                }
            }
        }
    
        private void FixupInnoAppUser(InnoAppUser previousValue)
        {
            if (previousValue != null && previousValue.Contact.Contains(this))
            {
                previousValue.Contact.Remove(this);
            }
    
            if (InnoAppUser != null)
            {
                if (!InnoAppUser.Contact.Contains(this))
                {
                    InnoAppUser.Contact.Add(this);
                }
                if (FK_InnoAppUser != InnoAppUser.Id)
                {
                    FK_InnoAppUser = InnoAppUser.Id;
                }
            }
        }
    
        private void FixupLanguage(Language previousValue)
        {
            if (previousValue != null && previousValue.Contact.Contains(this))
            {
                previousValue.Contact.Remove(this);
            }
    
            if (Language != null)
            {
                if (!Language.Contact.Contains(this))
                {
                    Language.Contact.Add(this);
                }
                if (FK_Language != Language.Id)
                {
                    FK_Language = Language.Id;
                }
            }
        }
    
        private void FixupArticleComment(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (ArticleComment item in e.NewItems)
                {
                    item.Contact = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (ArticleComment item in e.OldItems)
                {
                    if (ReferenceEquals(item.Contact, this))
                    {
                        item.Contact = null;
                    }
                }
            }
        }
    
        private void FixupContact_ContactAddress(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (Contact_ContactAddress item in e.NewItems)
                {
                    item.Contact = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (Contact_ContactAddress item in e.OldItems)
                {
                    if (ReferenceEquals(item.Contact, this))
                    {
                        item.Contact = null;
                    }
                }
            }
        }
    
        private void FixupContact_Competency(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (Contact_Competency item in e.NewItems)
                {
                    item.Contact = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (Contact_Competency item in e.OldItems)
                {
                    if (ReferenceEquals(item.Contact, this))
                    {
                        item.Contact = null;
                    }
                }
            }
        }
    
        private void FixupContact_TelecomType(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (Contact_TelecomType item in e.NewItems)
                {
                    item.Contact = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (Contact_TelecomType item in e.OldItems)
                {
                    if (ReferenceEquals(item.Contact, this))
                    {
                        item.Contact = null;
                    }
                }
            }
        }
    
        private void FixupOrder(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.NewItems != null)
            {
                foreach (Order item in e.NewItems)
                {
                    item.Contact = this;
                }
            }
    
            if (e.OldItems != null)
            {
                foreach (Order item in e.OldItems)
                {
                    if (ReferenceEquals(item.Contact, this))
                    {
                        item.Contact = null;
                    }
                }
            }
        }

        #endregion

    }
}
